


import 'package:flutter_fun_zjversion/provider/view_state_model.dart';

abstract class ViewStateListModel<T> extends ViewStateModel{
  List<T> list = [];
  
  initData() async{
    setBusy(true);
    await refresh(init:true);
  }
  // 下拉刷新
  refresh({bool init = false}) async {
    try {
      List<T> data = await loadData();
      if (data.isEmpty) {
        setEmpty();
      } else {
        onCompleted(data);
        list = data;
        if (init) {
          //改变页面状态为非加载中
          setBusy(false);
        } else {
          notifyListeners();
        }
      }
    } catch (e, s) {
      handleCatch(e, s);
    }
  }

  Future<List<T>> loadData();

  void onCompleted(List<T> data){}
  
}



